package com.hsj.eureka.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author:Teacher黄
 * @date:Created at 2020/01/01
 */
@Component
public class EurekaChangeStateListener {

    private Logger logger = LoggerFactory.getLogger(EurekaChangeStateListener.class);


    /**
     * 监听服务下线
     * @param e
     */
    @EventListener
    public void listenDown(EurekaInstanceCanceledEvent e){
        // 服务id
        String serverId = e.getServerId();
        // 服务名字
        String appName = e.getAppName();
        // 打印日志
        logger.info("服务名:{},服务id:{},下线了",appName,serverId);
    }

}
